function ShowProfiles() {
     var prDisplay=document.getElementById('own-profiles');
     if (prDisplay.style.height=='auto'){
         document.getElementById('profiles-display').innerHTML='Expand Profiles Display';
         prDisplay.style.height='125px';
     } else {
         document.getElementById('profiles-display').innerHTML='Collapse Profiles Display';
         prDisplay.style.height='auto';
     }
}

function ReadMore() {
     document.getElementById('read-more').style.height='auto';
     document.getElementById('read-less-link').style.position='absolute';
     document.getElementById('read-less-link').style.top='-5px';
}

function ReadLess() {
     document.getElementById('read-more').style.height='18px';
     document.getElementById('read-less-link').style.position='relative';
     document.getElementById('read-less-link').style.top='5px';
}


var xmlHttp
function LoadMovie(refno) {
      document.getElementById('video-player-bg').style.display = 'block';
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!\nMember Gallery cannot be displayed.");
        return;
      } 
      var url="./[incl]/.member-online-gallery/video-profile-loader.php";
      url=url+"?refno="+refno+"&sid="+Math.random();
      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
} 

function stateChanged() { 
   if (xmlHttp.readyState==4){
       document.getElementById('video-player').innerHTML = xmlHttp.responseText; 
   } 
}

function GetXmlHttpObject() {
   var xmlHttp=null;
   try   {   // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest(); }
   catch (e) {   // Internet Explorer
        try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
   }
   return xmlHttp;
}


function CloseMovie() {
        document.getElementById('video-player-bg').style.display = 'none';
        document.getElementById('video-player').innerHTML = '';
}



function GoSubscribe(step){  
    if(step=='PayAsYouDate') {
        document.getElementById('subscribe-msg').style.display = 'block';
    } else {                         
        document.getElementById('subscribe-msg').style.display = 'none';
        document.getElementById('subscribe-form').style.display = 'block';
    }
}

function GMcPanelGo(actiontitle){
          window.location.assign('?cpanel='+actiontitle);
}

function SwitchLogin(){                               
          var gologin=document.getElementById('go-login');
          gologin.submit();
}

function FillNext(srcel, destel){                               
          var srcvalue=document.getElementById(srcel).value;
          document.getElementById(destel).value = srcvalue;
}

function GoEnter(utype, uid){                               
          document.getElementById('user-type').value = utype;
          document.getElementById('user-id').value = uid;
          SwitchLogin();
}

function GuestMemberConnectResponse(actiontitle){
          switch(actiontitle) {
                    case 'ProfileRequestSent':
                         document.getElementById('contact-numbers-request').style.display='block';
                         RedirectCounter();
                    break;
                    case 'GuestAccountDisplay':
                         var destination=new String(window.location);
                         destination=destination.slice(0,destination.indexOf('&'));
                         top.window.location.assign(destination);
                    break;
                    case 'GuestProfileDisplay':
                         document.getElementById('display-profile-update').submit();
                    break;
                    case 'GuestProfileCreate':
                         document.getElementById('profile-update').submit();
                    break;
                    case 'LoginMemberSuccess':
                          SwitchLogin();
                    break;
                    case 'LoginMemberError':
                         document.getElementById('login-m-error').innerHTML='The login details you entered were incorrect.<br />Please <a href="javascript:SwitchLogin();">click here</a> to use the Guest Member login screen.'; 
                    break;
                    case 'LoginGuestMemberSuccess':
                          SwitchLogin();
                    break;
                    case 'LoginGuestMemberError':
                         document.getElementById('login-g-error').innerHTML='The login details you entered were incorrect.<br />Please check your email and type again your password.'; 
                    break;
                    case 'LoginGuestMemberErrorPassword':
                         document.getElementById('login').value='lost-pass';
                         document.getElementById('login-g-error').innerHTML='The login details you entered were incorrect.<br />Forgot your password? <a href="javascript:SwitchLogin();">Please click here</a>.'; 
                    break;
                    break;
                    case 'RegisterGuestMemberError':
                         document.getElementById('sign-in-error').innerHTML='This email is already registered on our system.<br />Please <a href="javascript:SwitchLogin();">click here</a> to use the Guest Member login screen.'; 
                    break;
                    case 'ResendGuestMemberSuccess':
                         document.getElementById('login').value='now';
                         document.getElementById('resendemail').value='';
                         document.getElementById('sign-in-error').innerHTML='The login data was resent to your email.<br />Please access your mail account then login <a href="javascript:SwitchLogin();">here</a>.'; 
                    break;
                    case 'ResendGuestMemberError':
                         document.getElementById('login').value='';
                         document.getElementById('sign-in-error').innerHTML='This email is not registered on our system.<br />Please <a href="javascript:SwitchLogin();">click here to sign up</a>.'; 
                    break;
                    case 'GuestMemberLogout':
                         window.location.reload();
                    break;
                    default: alert(actiontitle);
          }
}

function calcChar(src, rec, max) {
var x = 0;
max=max-1;
x = document.getElementById(src).value.length;
if ( x <= max ) {
document.getElementById(rec).style.backgroundColor = 'transparent'
document.getElementById(rec).innerHTML= "[Remain: "+ (max-x) + " symbols]";
}
else {
document.getElementById(rec).innerHTML=  "[Miss out: " + (x-max)+ " symbols]";
document.getElementById(rec).style.backgroundColor = '#ffa619';
}
}

function SelectGalleryMember(refno) {
   var refnumber=refno.slice(1);
   var allreferences=document.getElementById('gallery_references').value;
   var choosen_ref_count=Math.round(document.getElementById('choosen_ref_count').value);
   var allowed_ref_count=document.getElementById('allowed_ref_count').value;
   var background='url(http://www.topmatch-uk.com/[img]/transparent.gif) repeat center';
   if(allreferences.search(refnumber) >= 0) {
      allreferences=allreferences.replace(refnumber+", ", "");
      choosen_ref_count=choosen_ref_count-1;
   } else {
      if(choosen_ref_count<3 || allowed_ref_count == 'unlimited') {
         allreferences=allreferences+refnumber+"\, ";
         background='url(http://www.topmatch-uk.com/[img]/gallery_choosen.png) no-repeat 344px 78px';
         choosen_ref_count=choosen_ref_count+1;
      } else { 
         alert("You have already chosen 3 members from the gallery!\nNo further selections are allowed.\nTo allow further selections, please publish your own profile first.");
      }
   }
document.getElementById('choosen_ref_count').value=choosen_ref_count;
document.getElementById('gallery_references').value=allreferences;
document.getElementById(refno).style.background=background;
}

function RequestChoosenProfiles() {
      var choosenprofiles=document.getElementById('gallery_references').value;
      if(choosenprofiles!=null && choosenprofiles.length > 5 ) {
            var field = document.getElementById('cmf')
            if(field != null) {
                  document.getElementById('contact-numbers-request').style.display='block';
                  document.getElementById('request-button').style.display='none';
            } else {
                  var profileform=document.getElementById('profile-request-form');
                  profileform.submit();
            }

      } else {
            alert("Please select a Member Profile first! \n\n To Select (Deselect) Profile, just click on it.");
      }
}

function RequestProfilesContact(sel){ 
var field = document.getElementById('cmf');
   switch(sel.options.selectedIndex){ 
          case 1: field.innerHTML=document.getElementById('choose-phone').innerHTML;
                  field.style.display="block";
          break;
          case 2: field.innerHTML=document.getElementById('choose-email').innerHTML;
                  field.style.display="block";
          break;
          default: field.innerHTML="";
                   field.style.display="none";
   } 
}

var counttimer
var z=20;
function RedirectCounter() {
   if(z>0){
      document.getElementById('seconds-counter').innerHTML=z;
      z=z-1;
      counttimer=setTimeout("RedirectCounter()",1000);
   } else {
      document.getElementById('goredirect').click();
   }
}